#ifndef BOARD_H
#define BOARD_H

#include <QWidget>
#include <QPainter>
#include "piece.h"
#include "step.h"


class MainWindow;

class Board : public QWidget
{
    Q_OBJECT
public:
    explicit Board(MainWindow* _mainWindow,QWidget *parent = 0);
    void setMainWindow(MainWindow* winWindows);

    void init();
    void paintEvent(QPaintEvent *);
    void mouseReleaseEvent(QMouseEvent *event);
    virtual void clickHandler(int clickId, int row, int col);
    bool canMove(int id, int row, int col);
    int getPiece(int row, int col); //判断该行列位置有没没棋子并返回ID
    int countAtLine(int, int, int, int); //统计直线上棋子个数
    void movePiece(int id, int row, int col); //移动第id个棋子到row行col列
    void saveStep(int fromId, int rowTo, int colTo, int targetId);
    bool checkWin();
    void backOne();

protected:
    MainWindow* mainWindow;
    Piece pieces[32];
    int selectId;
    bool isRedTurn;
    QVector<Step*> steps;
    int redStep;
    int blackStep;
    bool isNetGame=false;

signals:
public slots:
    void undoBoard();
    void resetBoard();
    void backGame();
    void timeout(int value);
};

#endif // BOARD_H
